package com.bigdata.service.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.core.validate.QueryGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.vo.HistoryRecordsVo;
import com.bigdata.service.domain.bo.HistoryRecordsBo;
import com.bigdata.service.service.IHistoryRecordsService;
import com.bigdata.common.core.page.TableDataInfo;

/**
 * 地图预警
 *
 * @author ruoyi
 * @date 2025-08-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/records")
public class HistoryRecordsController extends BaseController {

    private final IHistoryRecordsService iHistoryRecordsService;

    /**
     * 查询地图预警列表
     */
    @SaCheckPermission("service:records:list")
    @GetMapping("/list")
    public TableDataInfo<HistoryRecordsVo> list(HistoryRecordsBo bo, PageQuery pageQuery) {
        return iHistoryRecordsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出地图预警列表
     */
    @SaCheckPermission("service:records:export")
    @Log(title = "地图预警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HistoryRecordsBo bo, HttpServletResponse response) {
        List<HistoryRecordsVo> list = iHistoryRecordsService.queryList(bo);
        ExcelUtil.exportExcel(list, "地图预警", HistoryRecordsVo.class, response);
    }

    /**
     * 获取地图预警详细信息
     *
     * @param recordId 主键
     */
    @SaCheckPermission("service:records:query")
    @GetMapping("/{recordId}")
    public R<HistoryRecordsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(iHistoryRecordsService.queryById(recordId));
    }

    /**
     * 新增地图预警
     */
    @SaCheckPermission("service:records:add")
    @Log(title = "地图预警", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HistoryRecordsBo bo) {
        return toAjax(iHistoryRecordsService.insertByBo(bo));
    }

    /**
     * 修改地图预警
     */
    @SaCheckPermission("service:records:edit")
    @Log(title = "地图预警", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HistoryRecordsBo bo) {
        return toAjax(iHistoryRecordsService.updateByBo(bo));
    }

    /**
     * 删除地图预警
     *
     * @param recordIds 主键串
     */
    @SaCheckPermission("service:records:remove")
    @Log(title = "地图预警", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(iHistoryRecordsService.deleteWithValidByIds(Arrays.asList(recordIds), true));
    }
}
